<?php

namespace App\Http\Controllers\admin;

use App\Dao\VipSettingsDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;
use App\Validate\Logic\VipSettingsLogic;

class VipSettingsController extends BaseController
{
    /**
     * Created by PhpStorm.
     * @purpose VIP列表
     * @Author: fhc
     * @Time: 2023/5/10 13:17
     */
    public function vips(){
        if(getIsHasPage()){
            return Code::message('',200,VipSettingsDao::get_vips_menu(request()->all()));
        }
        return view('admin.vips.vips');
    }

    /**
     * Created by PhpStorm.
     * @purpose 添加vip
     * @Author: fhc
     * @Time: 2023/5/10 13:18
     * @throws SysExceptions
     */
    public function add_vip(VipSettingsLogic $logic){
        if(isPost()){
            $params = request()->all();
            $logic->add_vip($params);
            VipSettingsDao::add_vip($params);
            return  Code::message('添加成功');
        }
        return view('admin.vips.add_vip');
    }

    /**
     * Created by PhpStorm.
     * @purpose 修改vip
     * @Author: fhc
     * @Time: 2023/5/10 13:18
     */
    public function edit_vip(VipSettingsLogic $logic){
        if(isPost()){
            $params = request()->all();
            $logic->edit_vip($params);
            VipSettingsDao::edit_vip($params);
            return  Code::message('添加成功');
        }
        $info = VipSettingsDao::get_vip_info(request()->all());
        return view('admin.vips.edit_vip',[
            'info'=>$info
        ]);
    }


    public function del_vip(VipSettingsLogic $logic): array
    {
        $params = [
            'vip_id'=>request('id')
        ];
        $logic->del_vip($params);
        VipSettingsDao::del_vip($params);
        return Code::message('删除成功',200);
    }


}
